import { Injectable } from '@nestjs/common';
import { AppLoggerService } from './logger.service';

@Injectable()
export class DatabaseLoggerService {
  private readonly logger = new AppLoggerService('Database');

  logQuery(query: string, parameters?: any[], queryRunner?: any) {
    this.logger.dbQuery(query, parameters);
  }

  logQueryError(error: string, query: string, parameters?: any[], queryRunner?: any) {
    this.logger.dbError(new Error(error), query);
  }

  logQuerySlow(time: number, query: string, parameters?: any[], queryRunner?: any) {
    this.logger.warning(`Slow query detected: ${time}ms - ${query}`, 'Database');
  }

  logSchemaBuild(message: string, queryRunner?: any) {
    this.logger.debug(`Schema build: ${message}`, 'Database');
  }

  logMigration(message: string, queryRunner?: any) {
    this.logger.info(`Migration: ${message}`, 'Database');
  }

  log(level: 'log' | 'info' | 'warn' | 'error', message: any, queryRunner?: any) {
    switch (level) {
      case 'log':
        this.logger.debug(message, 'Database');
        break;
      case 'info':
        this.logger.info(message, 'Database');
        break;
      case 'warn':
        this.logger.warning(message, 'Database');
        break;
      case 'error':
        this.logger.error(message, undefined, 'Database');
        break;
    }
  }
}

